﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataModel;
using ZedGraph;
using ZedGraph.Web;
using System.Drawing;
using System.Drawing.Imaging;

namespace Web
{
    public partial class products : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ZedGraphWeb1.RenderGraph += ZedGraphWeb1_RenderGraph;
            if (!this.IsPostBack)
            {

            }
        }

        public void RefeshZedGraph() {
            this.ZedGraphWeb1.AxisChanged = true;
        }

        void ZedGraphWeb1_RenderGraph(ZedGraphWeb webObject, Graphics g, MasterPane pane)
        {
            //throw new NotImplementedException();
            GraphPane myPane = pane[0];
            myPane.Title.Text = "预订订单 数量-日期折线图";
            myPane.XAxis.Title.Text = "日期";
            myPane.YAxis.Title.Text = "数量";
            myPane.XAxis.Type = AxisType.Date;
            myPane.XAxis.Scale.Format = "MM-dd";

            myPane.LineType = LineType.Stack;

            double[] lineBookOrder = { 20.0,40.0,199.0};
            double[] lineBookOrder2 = lineBookOrder.Reverse().ToArray();
            LineItem myCurve = myPane.AddCurve("预订订单数", lineBookOrder, lineBookOrder2, Color.Red, SymbolType.Diamond);
        }
  

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Bind();
        }


        protected void Bind()
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            if (!this.IsPostBack)
            {
                dsProduct tds = GetProduct();
                this.ViewState.Add("product_list", tds);


            }
            dsProduct tmp_ds = this.ViewState["product_list"] as dsProduct;
            if (this.Request.QueryString["id"] != null)
            {
                string id = this.Request.QueryString["id"];
                dsProduct ss = new dsProduct();
                ss.Merge(tmp_ds.Tables[0].Select("id=" + id));
                this.BindData(ss);
            }
            else
            {
                this.BindData(tmp_ds);
            }
        }
        protected dsProduct GetProduct()
        {
            daProduct daP = new daProduct();
            dsProduct dd = new dsProduct();
            dd.Merge(daP.GetProductList());
            return dd;
        }

        protected void BindData(dsProduct product)
        {

            this.listProduct.DataSource = product.Tables[0].DefaultView;
            this.listProduct.DataBind();
        }

        protected void BindData()
        {
            int index = -1;
            bool needquery = Request.QueryString.HasKeys() && Request.QueryString["id"] != null;
            if (needquery)
            {
                int.TryParse(Request.QueryString["id"].ToString(), out index);
            }

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("imageurl", typeof(string));
            ds.Tables.Add(dt);

            dt.Rows.Add("1", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("1", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("1", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("1", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("1", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("1", "acb", "~/images/heroAccent.png");

            dt.Rows.Add("2", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("2", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("2", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("2", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("2", "acb", "~/images/heroAccent.png");
            dt.Rows.Add("2", "acb", "~/images/heroAccent.png");

            DataView dv = dt.DefaultView;
            if (needquery)
            {
                dv.RowFilter = "id='" + index.ToString() + "'";
            }

            // DataTable dt1 =dt.Select("id='" + index.ToString()+"'"); 
            this.listProduct.DataSource = dv;
            this.listProduct.DataBind();
        }

        protected void btn_print_Click(object sender, EventArgs e)
        {
          //this.ZedGraphWeb1.pan
        }
    }
}